<?php
session_start();
error_reporting( E_ALL & ~E_NOTICE);

function mysqlConn()
{
   $con = mysql_connect("localhost", "root", "abcdef");
   $con = mysql_select_db("aleeda");
   return $con;
}
function out_print($str)
{
   echo $str."<br />\n";
}
function returnName()
{
   $name = "Aleeda";
   return $name;
}

function userSelect($session, $request)
{
   $query = mysql_query("SELECT ".$request." FROM users WHERE username = '".$session."'") or die("");
   $query = mysql_result($query, 0);
   return $query;
}
function cmsGetString($where)
{
   $query = mysql_query("SELECT str_content FROM cms_strings WHERE str_key = '".$where."'");// or die("");
   $query = mysql_result($query, 0);
   return $query;
}
function loginStartSession($username, $password)
{
   $user = mysql_real_escape_string($username);
   $pass = sha1(mysql_real_escape_string($password));
   
   $query = mysql_query("SELECT * FROM users WHERE username = '".$user."'") or die("");
   $query = mysql_fetch_array($query);
  
   if($pass != $query['password'] || $user != $query['username'])
   {
      echo "Wrong details, please <a href='index.php'>try again</a>";
   }
   elseif($pass == "")
   {
      echo "Wrong details, please <a href='index.php'>try again</a>.";
   }
   elseif($user == "")
   {
      echo "Wrong details, please <a href='index.php'>try again</a>.";
   }
   else
   {
    $_SESSION['name'] = $user;
    header("Location: me");
   }
   return $query;
}
function killSession($session)
{
   session_destroy();
   header("Location: index");
}
function listNews()
{
   $result = mysql_query("SELECT * FROM cms_news_articles ORDER BY id ASC");
   while($row = mysql_fetch_array($result))
   {
        echo '<div class="topstory" style="background-image: url('.$row["topstory"].')">';
	    echo '<h4>Latest news</h4>';
	    echo '<h3><a href="/articles/'.$row["id"].'">'.$row["title"].' </a></h3>';
	    echo '<p class="summary">';
	    echo $row["short_text"];
	    echo '</p>';
		echo '<p>';
	    echo '<a href="/articles/'.$row["id"].'">Read more &raquo;</a>';
	    echo '</p>';
	    echo '</div>';
		

   }
}
?>